<?php
namespace Home\Controller;
use Think\Controller;
class ZhanghuController extends Controller {
   public function index() {
           if($_SESSION['yonghuname']){
          
           $user=M('user');
        $userid = $_SESSION['id'];
        $data['id'] = $userid;
        
        $usermoney=$user->where($data)->field('yue')->select();//用户所有钱数
          $this->assign('money', $usermoney);
        $zhifupad=$user->where($data)->field('zhifupad')->find();
          
       if (empty($zhifupad['zhifupad'])) {
                 $zhifuminfo = '<div class="top clearfloat box-s">                
                <a href="http://niceweekend.cc/jieyue/index.php/Home/Zhanghu/zhifum" class="fr czhi">前往设置支付密码</a>
                </div>  ';
                $this->assign('zhifuminfo',$zhifuminfo);

        } 
                       
           $this->display();
        } else {
            $this->error("您还未登录！", U('My/my'));
        }
        }

        public function tixian(){
            $this->display();
        }
        
        public function congzhi(){
            $this->display();
        }

        public function zhifumi() {
               $userid = $_SESSION['id'];
               $pwd = $_POST['pwd'];
               $repwd = $_POST['repwd'];
             if(!$_POST['pwd'] || !$_POST['repwd']){
                  $this->error('支付密码不能为空');  
             }


             if($pwd != $repwd) {
                 $this->error('两次输入的密码不一致');
             } else {
                $data['id'] = $userid;
                $arr = array('zhifupad'=>$pwd);
                $info = M('user')->where($data)->save($arr);
             }

             if($info){
                $this->success('设置支付密码成功',U('Home/My/my'));
             }
                
             } 

             public function zhifum(){
                $this->display();
             }
}